<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org" th:with="title='订单管理',active='order'" xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity5">
<header th:replace="back/header::headerFragment(${title},${active})"></header>
<head>

</head>
<body class="fixed-left">
<div id="wrapper">
    <div th:replace="back/header::header-body"></div>
    <div class="content-page">
        <div class="content">
            <div class="container">
                <div class="row">
                    <div class="col-sm-12">
                        <h4 class="page-title">订单管理</h4>
                    </div>
                    <div class="col-md-12">
                        <table class="table table-striped table-bordered">
                            <thead>
                            <tr>
                                <th>订单号</th>
                                <th>订单时间</th>
                                <th>订单金额</th>
                                <th>当前状态</th>
                                <th>操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            <th:block th:each="order : ${orderList}">
                                <tr th:id="${order.id}">
                                    <td>
                                        <a th:href="@{'/order/'+${order.id}}" th:text="${order.id}" target="_blank"></a>
                                    </td>
                                    <td><th:block th:text="${#dates.format(order.createDate,'yyyy-MM-dd HH:mm:ss')}"/></td>
                                    <td><th:block th:text="${order.totalAmount}"/></td>
                                    <td th:if="${order.status} eq 0"><th:block />已退款</td>
                                    <td th:if="${order.status} eq 1"><th:block />待配送</td>
                                    <td th:if="${order.status} eq 2"><th:block/>配送中</td>
                                    <td th:if="${order.status} eq 3"><th:block/>已确定到达</td>
                                    <td th:if="${order.status} eq 4"><th:block />退款中</td>
                                    <td sec:authorize="hasRole('customer')">
                                        <a th:href="@{'/order/'+${order.id}}"
                                           class="btn btn-primary btn-sm waves-effect waves-light m-b-5">
                                           <i class="fa fa-edit"></i> <span>查看详情</span></a>
                                        <a href="javascript:void(0)" th:onclick="'delArticle('+${order.id}+');'"
                                           class="btn btn-danger btn-sm waves-effect waves-light m-b-5">
                                            <i class="fa fa-trash-o"></i> <span>申请退款</span></a>
                                        <a th:if="${order.status} eq 2" class="btn btn-warning btn-sm waves-effect waves-light m-b-5" href="javascript:void(0)">
                                            <i class="fa fa-rocket"></i> <span>确认收货</span></a>
                                    </td>
                                    <td sec:authorize="hasRole('business')">
                                        <a th:href="@{'/order/'+${order.id}}"
                                           class="btn btn-primary btn-sm waves-effect waves-light m-b-5">
                                            <i class="fa fa-edit"></i> <span>查看详情</span></a>
                                        <a th:if="${order.status} eq 1" href="javascript:void(0)" th:onclick="'toSend('+${order.id}+');'"
                                           class="btn btn-danger btn-sm waves-effect waves-light m-b-5">
                                            <i class="fa fa-trash-o"></i> <span>去发货</span></a>
                                        <a th:if="${order.status} eq 2" href="javascript:void(0)" th:onclick="'delArticle('+${order.id}+');'"
                                           class="btn btn-danger btn-sm waves-effect waves-light m-b-5">
                                            <i class="fa fa-trash-o"></i> <span>配送中</span></a>
                                        <a th:if="${order.status} eq 4" href="javascript:void(0)" th:onclick="'delArticle('+${order.id}+');'"
                                           class="btn btn-danger btn-sm waves-effect waves-light m-b-5">
                                            <i class="fa fa-trash-o"></i> <span>确定退款</span></a>
                                        <a class="btn btn-warning btn-sm waves-effect waves-light m-b-5" href="javascript:void(0)">
                                            <i class="fa fa-rocket"></i> <span>预览</span></a>
                                    </td>
                                </tr>
                            </th:block>

                            </tbody>
                        </table>
<!--                        <div th:replace="comm/paging :: pageAdminNav(${articles})"></div>-->
                    </div>
                </div>
                <div th:replace="back/footer :: footer-content"></div>
            </div>
        </div>
    </div>
</div>
<div th:replace="back/footer :: footer"></div>
<script type="text/javascript">
    var tale = new $.tale();
    function toSend(id) {
        // 获取<meta>标签中封装的_csrf信息
        if(confirm('确定发出吗?')){
            $.ajax({
                type:'post',
                url : '/business/sendOrder',
                data: {id:id},
                dataType: 'text',
                success: function (result) {
                    if (result) {
                        toastr.option={
                            timeout:3000
                        }
                        toastr.success('发货成功');
                        window.location.reload();
                    } else {
                        window.alert(result || '发货失败')
                    }
                },
                error:function (result){
                    console.log('error')
                }
            });
        }
    }
</script>
</body>
</html>